package packet1;

import java.util.*;

public class meituan2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        sc.nextLine();
        String[] input = new String[2];
        for(int i = 0; i < 2; i++){
            input[i] = sc.nextLine();
        }
        Map<String, Integer> map = new HashMap<>();
        String[] name = input[1].split(" ");
        String[] hight = input[0].split(" ");
        for(int j = 0; j < m; j++)
        {
            map.put(name[j],Integer.parseInt(hight[j]));
        }
        List<Map.Entry<String,Integer>> list = new ArrayList<>(map.entrySet());
        /*
        Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
            @Override
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                return 0;
            }
        })

        Collections.sort(list, (o1, o2) -> {
            int re = o1.getValue().compareTo(o2.getValue());
            if(re == 0)
                re = o1.getKey().compareTo(o2.getKey());
            return re;
        });*/

        Collections.sort(list,new Comparator<Map.Entry<String,Integer>>() {
            //排序
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                int re = o1.getValue().compareTo(o2.getValue());
                if(re == 0)
                    re = o1.getKey().compareTo(o2.getKey());
                return re;
            }
        });

        for(Map.Entry<String,Integer> entry : list)
        {
            System.out.print(entry.getKey() + " ");
        }
    }
}
/*
4
176 170 176 176
beta tom alpha bamma
 */
